//
//  ViewController.swift
//  BarCode
//
//  Created by xxcao on 2017/3/29.
//  Copyright © 2017年 MobileArtisan. All rights reserved.
//

import UIKit

class BCRootViewController: BCFatherViewController {
    
    let codeBtn = UIButton().then {
        $0.setImage(UIImage(named: "scanIcon"), for: .normal)
        $0.setImage(UIImage(named: "scanIcon"), for: .highlighted)
        $0.addTarget(self, action: #selector(clickBarCodeBtnAction(sender:)), for: .touchUpInside)
        $0.showsTouchWhenHighlighted = true
    }
    
    let tipsLabel = UILabel().then {
        $0.text = "点击开扫"
        $0.textAlignment = .center
        $0.font = UIFont.boldSystemFont(ofSize: 24)
        $0.textColor = UIColor.darkText
    }
    
    override func viewDidLoad() {
        super.viewDidLoad()
        title = "扫码"
        setNavigationItem()
        
        view.addSubview(codeBtn)
        codeBtn.snp.makeConstraints { (make) in
            make.width.equalTo(200)
            make.height.equalTo(200)
            make.centerY.equalToSuperview().offset(-44)
            make.centerX.equalToSuperview()
        }
        
        view.addSubview(tipsLabel)
        tipsLabel.snp.makeConstraints { make in
            make.height.equalTo(44)
            make.left.equalTo(44)
            make.right.equalTo(-44)
            make.top.equalTo(codeBtn.snp.bottom).offset(16)
        }
        
        let tap = UITapGestureRecognizer(target: self, action: #selector(clickBarCodeBtnAction(sender:)))
        tipsLabel.addGestureRecognizer(tap)
        tipsLabel.isUserInteractionEnabled = true

    }

    func setNavigationItem() {
        //left
        
        let leftNaviBarItem = UIBarButtonItem(title: "人员", style: .plain, target: self, action: #selector(leftBarItemAction))
        leftNaviBarItem.image = UIImage(named: "humanIcon")
        navigationItem.leftBarButtonItem = leftNaviBarItem
        
        
        //right
        customRightBarItem(str: "设置", imgStr: "settingIcon")
    }
    
    func leftBarItemAction() {
        let searchVC = BCSearchViewController()
        //返回选中搜索的结果
        searchVC.didSelectedItem { (item) in
            print(item!)
        }
        searchVC.pageFrom = "Main"
        Common.customPushAnimationFromNavigation(nav: navigationController!, toViewController: searchVC, type: "cube", subType:kCATransitionFromLeft, duration: 0.5)
    }
    
    override func rightBarItemAction() {
        let settingVC = BCSettingViewController()
        navigationController?.pushViewController(settingVC, animated: true)
    }
    override func viewWillAppear(_ animated: Bool) {
        super.viewWillAppear(animated)
        if isHasNewVersion {
            self.pointI?.isHidden = false
        } else {
            self.pointI?.isHidden = true
        }
    }
    
    @objc private func clickBarCodeBtnAction(sender: Any) {
        //二维码容器
        //add animation
        let scanVC = BCScanViewController()
        scanVC.pageFrom = "Main"
        Common.customPushAnimationFromNavigation(nav: navigationController!, toViewController: scanVC, type: "cameraIrisHollowOpen", subType:kCATransitionFromRight, duration: 0.618)
    }
}
